
    <body>
        <div class="x-body">
            <form action="" method="post" class="layui-form layui-form-pane">
                <div class="layui-form-item">
                    <label for="name" class="layui-form-label"  >
                        <span class="x-red">*</span>角色名
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="name" value="<?php echo $info['title'] ?>" name="title" required="" lay-verify="required"
                        autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">
                        拥有权限
                    </label>
                    <table  class="layui-form-item layui-table layui-input-block">
                        <tbody>
                            <?php foreach ($cate as $k => $v) { ?>
                            <tr>
                                <td><?php echo $k ?></td>
                                <td>
                                    <div class="layui-input-block">
                                    <?php foreach ($v as $key => $vv) { ?>

                                        <input <?php foreach ($rule as  $v) {
                                           if ($v==$vv['rid']) {
                                               echo 'checked';
                                           }
                                        } ?>  type="checkbox" value="<?php echo $vv['rid'] ?>" name="<?php echo $vv['title'] ?>" lay-skin="primary" title="<?php echo $vv['title'] ?>" >
                                        <div class="layui-unselect layui-form-checkbox layui-form-checked" lay-skin="primary">
                                            <span><?php echo $vv['title'] ?></span>
                                            <i class="layui-icon"></i>
                                        </div>
                                    <?php } ?>
                                    </div>
                                </td>
                            </tr>
                            <?php } ?>
                        </tbody>
                    </table>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label for="desc" class="layui-form-label">
                        描述
                    </label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入内容" id="desc" name="desc" class="layui-textarea"><?php echo $info['desc'] ?></textarea>
                        <input type="hidden" name="id" value="<?php echo $info['id'] ?>">
                    </div>
                </div>
                <div class="layui-form-item">
                <button class="layui-btn" lay-submit="" lay-filter="save">保存</button>
              </div>
            </form>
        </div>
        <script>
        

        layui.use(['form','layer'], function(){
            $ = layui.jquery;
            var form = layui.form()
            ,layer = layui.layer;

            

              //监听提交
            form.on('submit(save)', function(data){

                data.field.num= '';   //设定空字符串 
                //将选中的ID 循环放进 data
                for (var i = 0;i <$('.layui-input-block input:checked').length; i++) {
                    data.field.num += $('.layui-input-block input:checked').eq(i).val()+',';
                };
                // alert(data.field.num);
                // return false;
                $.ajax({
                    url: '{:U('admin/admin/role_save')}',
                    type: 'POST',
                    dataType: 'json',
                    data: data.field,
                })
                .done(function(response) {
                    if (response.error==1) {
                        layer.alert(response.info, {icon: 2})
                    }else{
                        layer.alert(response.info, {icon: 6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            parent.location.reload();
                        });
                    };
                })
                .fail(function(response) {
                    console.log("error");
                })
                
                return false;
            });
              
              
        });
        </script>

    </body>

</html>